package game.buildings;

import java.awt.Point;
import java.awt.Polygon;

import game.GameObject;

/**
 *	@(#)Grave.java
 *
 *	The <code>Grave</code> class represents a grave.
 *	Graves block city spaces and buildings.
 *
 *	@author Grzegorz Kobiela
 *	@version 1.09 2008/5/15
 */
public final class Grave
extends CityBuilding
implements Indexed
{
	/** The index (1 - 20). */
	private int index;

	/** The blocked object. */
	private GameObject blocked;

	/** The recent location. */
	private Point recent;

	/**
	 *	Creates a new <code>Grave</code> instance.
	 */
	public Grave() {
		super(BuildingType.GRAVE);
		polygon = new Polygon(new int[]{0, 1, 1, 0}, new int[]{0, 0, 1, 1}, 4);
		index = (int)(20 * Math.random()) + 1;
		limitUsed = 0;
		graves = null;
		blocked = null;
		recent = null;
	}

	/**
	 *	Sets the blocked object to the given value.
	 *	@param blocked the new blocked object
	 */
	public void setBlocked(GameObject blocked) {
		update(this.blocked = blocked);
	}

	/**
	 *	Returns the blocked object.
	 *	@return the blocked object
	 */
	public GameObject getBlocked() {
		return blocked;
	}

	/**
	 *	Sets the recent location to the given value.
	 *	@param location the new location
	 */
	public void setRecentLocation(Point location) {
		recent = (location != null ? new Point(location) : null);
	}

	/**
	 *	Returns the recent location.
	 *	@return the recent location
	 */
	public Point getRecentLocation() {
		return (recent != null ? new Point(recent) : null);
	}

	/**
	 *	Returns the index of the indexed building.
	 *	@return the index
	 */
	public int getIndex() {
		return index;
	}

	/**
	 *	Adds the given grave to the building.
	 *	@param grave the grave
	 */
	@Override
	public void addGrave(Grave grave) {}

	/**
	 *	Returns true if the building has the given grave on it.
	 *	@return true if the building has the given grave on it
	 */
	@Override
	public boolean hasGrave(Grave grave) {
		return false;
	}

	/**
	 *	Removes the given grave from the building.
	 *	@param grave the grave
	 */
	@Override
	public void removeGrave(Grave grave) {}

	/**
	 *	Graves are always enabled.
	 *	@return true
	 */
	@Override
	public boolean isEnabled() {
		return true;
	}
}